//
//  HomeClassifyItemView.m
//  TerritoryShopkeeper
//
//  Created by xiaowu on 2017/12/4.
//  Copyright © 2017年 ZDQK. All rights reserved.
//

#import "HomeClassifyItemView.h"

@interface HomeClassifyItemView ()

@property (nonatomic, strong) UIButton *button;

@end

@implementation HomeClassifyItemView

- (instancetype)init {
    self = [super init];
    if (self) {
        [self configure];
    }
    return self;
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self configure];
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.imageView.frame = CGRectMake(self.width * 0.5 - 20, 10, 40, 40);
    self.titleLabel.frame = CGRectMake(0, self.imageView.bottom + 5, self.width, 17);
    self.button.frame = self.bounds;
}

#pragma mark - Method
- (void)configure {
    [self addSubview:self.imageView];
    [self addSubview:self.titleLabel];
    [self addSubview:self.button];
}

#pragma mark - Action
- (void)buttonClick:(UIButton *)sender {
    if (self.block) {
        self.block();
    }
}

#pragma mark - Getters
- (UIImageView *)imageView {
    if (!_imageView) {
        _imageView = [[UIImageView alloc] init];
        _imageView.size = CGSizeMake(40, 40);
        _imageView.layer.cornerRadius = 16;
        _imageView.clipsToBounds = YES;
    }
    return _imageView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = TextPingFangFontSize(12);
        _titleLabel.textColor = [UIColor blackTextColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLabel;
}

- (UIButton *)button {
    if (!_button) {
        _button = [UIButton buttonWithType:UIButtonTypeCustom];
        [_button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _button;
}

@end
